//
//  SinaVisitorView.m
//  MySinaWeiboProjectForOC
//
//  Created by apple on 2016/11/13.
//  Copyright © 2016年 WangChen. All rights reserved.
//

#import "SinaVisitorView.h"
#import "UILabel+extension.h"
#import "UIButton+extension.h"
#import <Masonry.h>

@interface SinaVisitorView ()

@property (nonatomic,weak) UIImageView *cycleView;
@property (nonatomic,weak) UIImageView *houseView;
@property (nonatomic,weak) UIImageView *backView;
@property (nonatomic,weak) UILabel *titleLbl;
@property (nonatomic,weak) UIButton *loginBtn;
@property (nonatomic,weak) UIButton *registerBtn;

@end


@implementation SinaVisitorView


- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}


#pragma mark
#pragma mark - 设置界面信息的方法
-(void)updateInfoWithTitle:(NSString *)title imageName:(NSString *)imageName isHome:(BOOL)isHome{
    
    self.cycleView.image = [UIImage imageNamed:imageName];
    self.titleLbl.text = title;
    if(isHome){
        
        CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        anim.repeatCount = CGFLOAT_MAX;
        anim.duration = 20;
        anim.toValue = @(M_PI * 2);
        
        [self.cycleView.layer addAnimation:anim forKey:nil];
        
    }else{
        self.houseView.hidden = YES;
        self.backView.hidden = YES;
        
    }
    
}


#pragma mark
#pragma mark - 设置界面
- (void)setupUI{
    
    //添加控件并关联属性
    UIImageView *cycleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    [self addSubview:cycleView];
    _cycleView = cycleView;
    
    UIImageView *backView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    [self addSubview:backView];
    _backView = backView;
    
    UIImageView *houseView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    [self addSubview:houseView];
    _houseView = houseView;
    
    UILabel *titleLbl = [[UILabel alloc]initWithTitle:@"点击登录卧了个槽了哈哈哈哈哈哈哈哈哈哈哈哈~~~" color:[UIColor grayColor] font:18];
    [self addSubview:titleLbl];
    _titleLbl = titleLbl;
    titleLbl.numberOfLines = 0;
    titleLbl.preferredMaxLayoutWidth = 220;
    
    UIButton *loginBtn = [[UIButton alloc]initWithTitle:@"登录" color:[UIColor grayColor] imageName:@"common_button_white"];
    [self addSubview:loginBtn];
    _loginBtn = loginBtn;
    
    UIButton *registerBtn = [[UIButton alloc]initWithTitle:@"注册" color:[UIColor orangeColor] imageName:@"common_button_white"];
    [self addSubview:registerBtn];
    _registerBtn = registerBtn;
    
    [loginBtn addTarget:self action:@selector(clickLoginBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [registerBtn addTarget:self action:@selector(clickRegistBtn) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    //设置约束
    [cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-80);
    }];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(cycleView);
    }];
    [houseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(cycleView);
    }];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(cycleView.mas_bottom).offset(20);
        make.centerX.equalTo(cycleView);
    }];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(titleLbl).offset(-60);
        make.top.equalTo(titleLbl.mas_bottom).offset(20);
        make.width.mas_equalTo(100);
    }];
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(titleLbl).offset(60);
        make.top.equalTo(loginBtn);
        make.width.equalTo(loginBtn);
    }];
    
    self.backgroundColor = [UIColor colorWithWhite:237/255.0 alpha:1];
    
    
    
}



#pragma mark
#pragma mark - 点击按钮的方法
-(void)clickLoginBtn{
    [self.delegate loginBtnDidClick];
}
-(void)clickRegistBtn{
    [self.delegate registBtnDidClick];
}



@end
